****** Table_6_1: Pre-modern Democracy
use data/LandCover_GRID_CELL_v9_short.dta, clear

*rename Elections Succession
*gen Demo_Murdock = 0 if Succession !=.
*replace Demo_Murdock = 1 if Succession == 6 | Succession == 7

keep year gid country_id Demo_Murdock predallports53_100km Statehood e_regionpol4 ocdistance rivdist crop pasture forest grass shrub savanna barren water mountains temp irrig_sum 
keep if year == 2000

*1) unrestricted
qui reg Demo_Murdock predallports53_100km if year == 2000
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_1.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(4) keep(predallports53_100km) replace
qui drop sample

*2)
qui reg Demo_Murdock predallports53_100km if Statehood > 1 & year == 2000
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_1.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(4) keep(predallports53_100km) append
qui drop sample

*3)
qui reg Demo_Murdock predallports53_100km if Statehood > 2 & year == 2000
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_1.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(4) keep(predallports53_100km) append
qui drop sample

*4)
qui reg Demo_Murdock predallports53_100km if Statehood > 3 & year == 2000
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_1.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(4) keep(predallports53_100km) append
qui drop sample

*5) regions
qui reg Demo_Murdock predallports53_100km i.e_regionpol4 if Statehood > 3 & year == 2000
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_1.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(4) keep(predallports53_100km) append
qui drop sample

*6) geographic covariates
qui reg Demo_Murdock predallports53_100km ocdistance rivdist crop pasture forest grass shrub savanna barren water mountains temp irrig_sum if Statehood > 3 & year == 2000
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_1.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(4) keep(predallports53_100km) append
qui drop sample

****** Table_6_2: Specification tests (PRIO Grid-cells)
use data/LandCover_GRID_CELL_v9_reduced.dta, clear
* polyarchy, 100-point scale
gen v2x_polyarchy_100 = (v2x_polyarchy / .924) * 100

* polyarchy, missing obs imputed
impute v2x_polyarchy lexical_index inc_chall_combined , gen(v2x_polyarchy_imp)
* 100-point scale
replace v2x_polyarchy_imp = v2x_polyarchy_imp * 100
gen v2x_polyarchy_imp_100 = (v2x_polyarchy_imp / 92.4) * 100
replace v2x_polyarchy_imp_100 = . if sovereign_Cojocaru ==.


*1) bivariate
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year,vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) replace
qui drop sample

*2) 2000
qui reg v2x_polyarchy_imp_100 predallports53_100km if year == 2000,vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*3) equator (distance to)
qui reg v2x_polyarchy_imp_100 predallports53_100km equator_distance i.year,vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*4) precipitation
qui reg v2x_polyarchy_imp_100 predallports53_100km c.prec_gpcc##c.prec_gpcc i.year, vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*5) river distance
qui reg v2x_polyarchy_imp_100 predallports53_100km rivdist i.year,vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*6) irrigation
qui reg v2x_polyarchy_imp_100 predallports53_100km irrig_sum i.year,vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*7) temperature
qui reg v2x_polyarchy_imp_100 predallports53_100km temp i.year,vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*8) agricultural zones
qui reg v2x_polyarchy_imp_100 predallports53_100km crop pasture forest grass shrub savanna barren water mountains i.year,vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*9) all covariates from previous tests
qui reg v2x_polyarchy_imp_100 predallports53_100km equator_distance c.prec_gpcc##c.prec_gpcc rivdist irrig_sum temp crop pasture forest grass shrub savanna barren water mountains i.year,vce(cluster gid)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_2.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample



******* Table_6_3: Specification tests (country level)
use data/Demo_book_country_3.dta, clear
* polyarchy, 100-point scale
gen v2x_polyarchy_100 = (v2x_polyarchy / .924) * 100

* polyarchy, missing obs imputed
impute v2x_polyarchy lexical_index inc_chall_combined , gen(v2x_polyarchy_imp)
* 100-point scale
replace v2x_polyarchy_imp = v2x_polyarchy_imp * 100
gen v2x_polyarchy_imp_100 = (v2x_polyarchy_imp / 92.4) * 100
replace v2x_polyarchy_imp_100 = . if sovereign_Cojocaru ==.


*1) bivariate
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) replace
qui drop sample

*2) area
qui reg v2x_polyarchy_imp_100 predallports53_100km area_imp_ext_corrected_ln i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*3) precipitation, as quadratic (following Haber)
qui reg v2x_polyarchy_imp_100 predallports53_100km c.prec_gpcc##c.prec_gpcc i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*4) irrigation potential (Bentzen et al)
*Share of land suitable for agriculture where irrigation can more than double agricultural production (land in Impact Class 5 as a share of land in Impact Classes 1-5).
*alternate measures: irri_impact4_5 irri_impact3_5 irri_impact2_5 irri_actcult irri1900 irri2000
qui reg v2x_polyarchy_imp_100 predallports53_100km irri_impact5 i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*5) river distance
qui reg v2x_polyarchy_imp_100 predallports53_100km rivdist_abs_new i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*6) ocean distance
qui reg v2x_polyarchy_imp_100 predallports53_100km ocdistance_abs_new i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*7) landlock
* the old landlock var (landlock) is not correctly coded. Brendan re-coded it.
qui reg v2x_polyarchy_imp_100 predallports53_100km landlock_new i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*8) island
qui reg v2x_polyarchy_imp_100 predallports53_100km Island i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*9) fish
qui reg v2x_polyarchy_imp_100 predallports53_100km suit50_mfish i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(suit50_mfish) append
qui drop sample

*10) resource dependence (Haber/Menaldo), using oil because it is more complete
* e_Total_Oil_Income_PC_ext: the same variable with values interpolated up to 2019 and missing values filled in with 0's
qui reg v2x_polyarchy_imp_100 predallports53_100km e_Total_Oil_Income_PC_ext i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*11) latitude
qui reg v2x_polyarchy_imp_100 predallports53_100km lp_lat_abst i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*12) tropical
qui reg v2x_polyarchy_imp_100 predallports53_100km tropical i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*13) temperature
qui reg v2x_polyarchy_imp_100 predallports53_100km avg_temp i.year,vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*14) frost days
qui reg v2x_polyarchy_imp_100 predallports53_100km frstdays i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*15) fertile soil
qui reg v2x_polyarchy_imp_100 predallports53_100km soil i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*16) desert
qui reg v2x_polyarchy_imp_100 predallports53_100km desert i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*17) elevation
qui reg v2x_polyarchy_imp_100 predallports53_100km eleva i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*18) ruggedness
qui reg v2x_polyarchy_imp_100 predallports53_100km rugged i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*19) agricultural suitability
qui reg v2x_polyarchy_imp_100 predallports53_100km suita i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*20) all vars previous vars 
qui reg v2x_polyarchy_imp_100 predallports53_100km lp_lat_abst Island landlock_new area_imp_ext_corrected_ln c.prec_gpcc##c.prec_gpcc rivdist_abs_new irri_impact5 tropical avg_temp frstdays soil desert eleva rugged suita i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*21) agricultural zones
qui reg v2x_polyarchy_imp_100 predallports53_100km crop pasture forest grass shrub savanna barren water mountains i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*22) regions 
qui reg v2x_polyarchy_imp_100 predallports53_100km i.e_regionpol4 i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_3.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample



****** Table_6_4:  Harbor Distance
* all harbor distance variables converted to 100km so they are comparable
use data/Demo_book_country_3.dta, clear
* polyarchy, 100-point scale
gen v2x_polyarchy_100 = (v2x_polyarchy / .924) * 100

* polyarchy, missing obs imputed
impute v2x_polyarchy lexical_index inc_chall_combined , gen(v2x_polyarchy_imp)
* 100-point scale
replace v2x_polyarchy_imp = v2x_polyarchy_imp * 100
gen v2x_polyarchy_imp_100 = (v2x_polyarchy_imp / 92.4) * 100
replace v2x_polyarchy_imp_100 = . if sovereign_Cojocaru ==.


*1) benchmark
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) replace
qui drop sample

*2) benchmark, logged
*gen predallports53_100km_ln = ln(predallports53_100km+1)
qui reg v2x_polyarchy_imp_100 predallports53_100km_ln i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km_ln) append
qui drop sample

*3) benchmark, quadratic
qui reg v2x_polyarchy_imp_100 c.predallports53_100km##c.predallports53_100km i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(c.predallports53_100km##c.predallports53_100km) append
qui drop sample

*4) predicted natural harbors (WPI 1953)
* gen prednatports53_100km = prednatports53_km / 100
qui reg v2x_polyarchy_imp_100 prednatports53_100km i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(prednatports53_100km) append
qui drop sample

*5) ports (WPI 1953)
* gen distallports53_100km = distallports53_km / 100
qui reg v2x_polyarchy_imp_100 distallports53_100km i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(distallports53_100km) append
qui drop sample

*6) natural harbors (WPI 1953)
* gen distnatports53_100km = distnatports53_km / 100
qui reg v2x_polyarchy_imp_100 distnatports53_100km i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(distnatports53_100km) append
qui drop sample

*7) ports (WPI 2017) 
* gen portdist_allports_100km = portdist_allports / 100000
qui reg v2x_polyarchy_imp_100 portdist_allports_100km i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(portdist_allports_100km) append
qui drop sample

*8) natural harbors (WPI 2017) 
* gen portdist_natural_100km = portdist_natural_km / 100
qui reg v2x_polyarchy_imp_100 portdist_natural_100km i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(portdist_natural_100km) append
qui drop sample

*9) ports (Lloyds)
* by country_id: ipolate portdist_loyds_km year, gen(portdist_loyds_km_ipo)
* gen portdist_loyds_ipo_100km = portdist_loyds_km_ipo / 100
qui reg v2x_polyarchy_imp_100 portdist_loyds_ipo_100km i.year,vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(portdist_loyds_ipo_100km) append
qui drop sample

*10) IV: predicted distance
qui ivregress 2sls v2x_polyarchy_imp_100 cc.year##c.year (distallports53_100km = predallports53_100km), vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(distallports53_100km) append
qui drop sample

*11) IV: ocean distance
qui ivregress 2sls v2x_polyarchy_imp_100 cc.year##c.year (distallports53_100km = ocdistance_abs_new), vce(cluster country_id)
qui local clusters=e(N_clust)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_4.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Clusters", `clusters', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(distallports53_100km) append
qui drop sample


****** Table_6_5:  Alternate Democracy Indices
use data/Demo_book_country_3.dta, clear
* polyarchy, 100-point scale
gen v2x_polyarchy_100 = (v2x_polyarchy / .924) * 100

* polyarchy, missing obs imputed
impute v2x_polyarchy lexical_index inc_chall_combined , gen(v2x_polyarchy_imp)
* 100-point scale
replace v2x_polyarchy_imp = v2x_polyarchy_imp * 100
gen v2x_polyarchy_imp_100 = (v2x_polyarchy_imp / 92.4) * 100
replace v2x_polyarchy_imp_100 = . if sovereign_Cojocaru ==.


*1) Polyarchy, augmented (benchmark)
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_5.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) replace
qui drop sample

*2) Polyarchy	
* converted to 100-point scale
qui reg v2x_polyarchy_100 predallports53_100km i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_5.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*3) Lexical	
* convert to 100-point scale
* gen lexical_index_100 = lexical_index * 16.666
qui reg lexical_index_100 predallports53_100km i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_5.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*4) Polity2
* convert to 100-point scale
* gen e_polity2_100 = (e_polity2 + 10) * 5
qui reg e_polity2_100 predallports53_100km i.year, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_5.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*5) Contestation
* already a 100-point scale
qui tobit inc_chall_combined predallports53_100km i.year,ll vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_5.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "Pseudo likelihood", e(ll)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample



****** Table_6_6. Sample Restrictions
use data/Demo_book_country_3.dta, clear
* polyarchy, 100-point scale
gen v2x_polyarchy_100 = (v2x_polyarchy / .924) * 100

* polyarchy, missing obs imputed
impute v2x_polyarchy lexical_index inc_chall_combined , gen(v2x_polyarchy_imp)
* 100-point scale
replace v2x_polyarchy_imp = v2x_polyarchy_imp * 100
gen v2x_polyarchy_imp_100 = (v2x_polyarchy_imp / 92.4) * 100
replace v2x_polyarchy_imp_100 = . if sovereign_Cojocaru ==.


*1) 
qui reg v2x_polyarchy_imp_100 predallports53_100km if year == 2000, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) replace
qui drop sample

*2) 
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if sovereign_Cojocaru == 1, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*3) 
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if sovereign_Cojocaru == 0, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*4)
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if e_regionpol4 != 1, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*5)
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if e_regionpol4 != 2, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*6)
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if e_regionpol4 != 3, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*7)
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if e_regionpol4 != 4, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*8)
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if e_regionpol4 != 5, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*9)
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if predallports53_100km  > 3, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample

*10)
qui reg v2x_polyarchy_imp_100 predallports53_100km i.year if predallports53_100km  < 10, vce(cluster country_id)
qui gen sample = e(sample)
qui tab country_id if sample == 1, nofreq
qui local countries=r(r)
qui tab year if sample == 1, nofreq
qui local years=r(r)
qui outreg2 using output/Table_6_6.doc, nor noni nonot nocon stats(coef tstat) addstat("Countries", `countries', "Years", `years', "R-squared", e(r2)) addn("*** p<0.01, ** p<0.05, * p<0.1") se bdec(3) keep(predallports53_100km) append
qui drop sample
